package com.cn.goodsadmin.dao.impl;

import com.cn.goodsadmin.dao.BaseDao;
import com.cn.goodsadmin.dao.IBalanceDao;
import com.cn.goodsadmin.po.Balance;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;


@Repository("balancedao")
public class BalanceDaoImpl extends BaseDao<Balance> implements IBalanceDao {

    public List<Balance> getAllBalance() throws Exception {
        final StringBuilder builder=new StringBuilder();
        builder.append("from Balance");
        return getHibernateTemplate().execute(new HibernateCallback<List<Balance>>() {
            public List<Balance> doInHibernate(Session session) throws HibernateException {
                Query query=session.createQuery(builder.toString());
                //query.setCacheable(true);
                return query.list();
            }
        });
    }
}
